import Request from 'utils/request';

import MerchantData from 'models/statistic/merchantData';
import GoodsStat from 'models/statistic/goodsStat';

export default class StatisticApi {
  static getMerchantStatData(search) {
    const apiName = 'api/dataview/queryBranchLocationAll';
    let postData = search.getObject();

    return Request.post(apiName, postData).then(res => {
      let merchantList = res.data;
      let merchants = [];
      for (let i = 0; i < merchantList.length; i++) {
        let merchant = merchantList[i];
        merchant = new MerchantData(merchant);
        if (merchant.lat === null || merchant.lng === null) {
          continue;
        }
        merchants.push(merchant);
      }
      return merchants;
    });
  }

  static getMerchantStatCount(){
    const apiName = 'api/dataview/wechatUserLoginCount';
    return Request.post(apiName).then(res => {
      return res.data;
    });
  }

  static getMajorTypeRateData(){
    const apiName = 'api/dataview/queryBranchPartnerDataAndMajorType';
    return Request.post(apiName).then(res=>{
      return res.data.majoyTypeCount;
    });
  }

  static getGoodStatData(){
    const apiName = 'api/dataview/queryGoodsModel';
    return Request.post(apiName).then(res=>{
      let goodsStat = new GoodsStat(res.data);
      return goodsStat;
    });
  }
}
